package com.atguigu.spring5_02.TestSpring5;/*
@author joker
@create 2022-03-17 17:24
untitled
*/

import com.atguigu.spring5_02.CollectionType.Stu;
import com.atguigu.spring5_02.autowire.Emp;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.atguigu.spring5_02.Bean.orders;

public class Test {
    public static void main(String[] args) {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanList01.xml");
        Stu aa = context.getBean("stu", Stu.class);
        for (String cours : aa.getCourses()) {
            System.out.println(cours);
        }
        System.out.println(aa.getList());
        System.out.println(aa.getMaps());
        System.out.println(aa.getSets());
    }
    /*bean的生命周期
    * (1) 通过构造器创建bean实例(无参数构造)
      (2) 为bean的属性设置值,和对其他bean的引用(调用set方法)
      (3) 调用bean的初始化的方法,(需要我们去配置初始化的方法)
      (4) bean可以使用了(对象获取到了)
      (5) 当容器关闭时,调用bean的销毁的方法(需要配置销毁的方法)* /
     */

    @org.junit.Test
    public void testBean5(){
        //这个是IOC容器的创建
        ApplicationContext context = new ClassPathXmlApplicationContext("beanLife.xml");
        orders or = context.getBean("orders",orders.class);
        //第四步,获得了创建的bean的对象
        System.out.println(or);
        //手动让bean实例销毁
        ((ClassPathXmlApplicationContext)context).close();
    }

    @org.junit.Test
    public void testBean6(){
        //手动装配
        ApplicationContext context = new ClassPathXmlApplicationContext("bean6.xml");
        Emp or = context.getBean("emp", Emp.class);
        System.out.println(or);

    }

}
